<script src="../utils/printLinkNode.js"></script>
<script type="text/javascript">

function ListNode(x){
    this.val = x;
    this.next = null;
}
let a = new ListNode(1)
let b = new ListNode(2)
let c = new ListNode(3)
a.next = b;
b.next = c;
let aa = new ListNode(4)
let bb = new ListNode(5)
let cc = new ListNode(6)
aa.next = bb;
bb.next = cc;
	
function Merge(pHead1, pHead2)
{
    let p1 = pHead1,    // 当前链表1指针
        p2 = pHead2;    // 当前链表2指针
    let p3 = new ListNode(),
        head3 = p3;
    while(p1!=null && p2!=null) {
        let head = new ListNode();
        p3.next = head
        p3 = head
        if(p1.val <= p2.val) {
            head.val = p1.val;
            p1 = p1.next;
        } else {
            head.val = p2.val;
            p2 = p2.next;
        }
    }
    
    if(p1 == null) {
        p3.next = p2
    } else {
        p3.next = p1
    }
    
    return head3.next
}

const head = Merge(a, aa)
printLinkNode(head)

</script>